package com.wanmait.wanmarecruit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wanmait.wanmarecruit.entity.Technology;
import com.wanmait.wanmarecruit.service.HonorsWonService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wanmarecruit.mapper.HonorsWonMapper;
import com.wanmait.wanmarecruit.entity.HonorsWon;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class HonorsWonServiceImpl extends ServiceImpl<HonorsWonMapper, HonorsWon> implements HonorsWonService {

    @Override
    public List<HonorsWon> getHonorsByUserId(Integer userId) {
        LambdaQueryWrapper<HonorsWon> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HonorsWon::getUserId,userId);
        return this.list(queryWrapper);
    }

    @Override
    public void saveSomeHonorsByUser(Integer userId, String[] existHor) {
        if (userId!=null) {
            LambdaQueryWrapper<HonorsWon> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(HonorsWon::getUserId,userId);
            this.remove(queryWrapper);
            List<HonorsWon> honorsWonList = new ArrayList<>();
            for (int i = 0; i < existHor.length; i++) {
                HonorsWon honorsWon = new HonorsWon();
                honorsWon.setHonorsWonInfo(existHor[i]);
                honorsWon.setUserId(userId);
                honorsWonList.add(honorsWon);
            }
            this.saveBatch(honorsWonList);
        }
    }
}
